#include<stdio.h>
#include<string.h>
#include"link.h"
void stu_help(void);

/*void test01()
{
	STU1 data1 = { 100,"德玛",59 };
	STU1 data2 = { 101,"达拉",89 };
	STU1 data3 = { 102,"蹦跶",79 };
	STU1 data4 = { 103,"僧",99 };
	STU1 data5 = { 104,"风男",39 };
	STU1* head = NULL;
	head = &data1;
	data1.next = &data2;
	data2.next = &data3;
	data3.next = &data4;
	data4.next = &data5;
	data5.next = NULL;

	STU1* pb = head;//定义一个pb  用来指向和移动
	while (pb != NULL)
	{
		printf("%d %s %f\n", pb->num, pb->name, pb->score);
		pb = pb->next;//移动到下一个
	}
}*/
int main(int argc, char* argv[])
{
	STU* head = NULL;//定义一个链表头 一定赋值为空
	stu_help();

	while (1)
	{
		char cmd[32]="";
		printf("请输入操作指令：\n");
		scanf_s("%s", cmd, (unsigned int)sizeof(cmd));
		if (strcmp(cmd, "help") == 0)
			{
				stu_help();
			}
		else if (strcmp(cmd, "insert") == 0)
			{
				STU tmp;
				printf("输入要插入的数据：（学号 名字 成绩）\n");
				scanf_s("%d %s %f", &tmp.num, &tmp.name, 31, &tmp.score);
				//将tmp  插入到head所指向的链表中
				head = insert_link(head, tmp);
			}
		else if (strcmp(cmd, "print") == 0)
			{
				print_link(head);
			}
		else if (strcmp(cmd, "search") == 0)
			{
			char name[32] = "";
			STU* ret = NULL;
			printf("请输入查询的名字\n");
			scanf_s("%s", name, (unsigned int)sizeof(name));
			ret = search_link(head, name);
			if (ret != NULL)
			{
				printf("num=%d,name=%s,score=%f\n", ret->num, ret->name, ret->score);
			}
			else
			{
				printf("数据没找到%s\n",name);
			}
			}
		else if (strcmp(cmd, "delete") == 0)
			{
			char name[32] = "";
			printf("请输入要删除的名字：\n");
			scanf_s("%s", name, (unsigned int)sizeof(name));
			head = detele_link(head, name);
			}
		else if (strcmp(cmd, "reverse") == 0)
		{
			head = reverse_link(head);
		}
		else if (strcmp(cmd, "sort") == 0)
		{
			head = sort_link(head);
		}
		else if (strcmp(cmd, "free") == 0)
			{
				head = free_link(head);
			}
		else if (strcmp(cmd, "quit") == 0)
			{
			//释放链表
			head = free_link(head);
			break;
			}
		else
		{ 
			printf("请输入合法字符\n"); 
		}
	}
	return 0;
}
void stu_help(void)
{
	printf("############################\n");
	printf("#     help-帮助信息        #\n");
	printf("#    insert-插入链表       #\n");
	printf("#    print-遍历链表        #\n");
	printf("# search-查询链表节点信息  #\n");
	printf("# delete-删除链表节点信息  #\n");
	printf("#     reverse-逆序链表     #\n");
	printf("#      sort-排序链表       #\n");
	printf("#      free-释放链表       #\n");
	printf("#        quit-退出         #\n");
	printf("############################\n");
}